﻿using MIO.Client.Util;
using MoblieIMSDK.DotNet.FastJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MIO.Client.Protocal
{
    public class Packet
    { 
        private int type = 0;
        private String subType = "";
        private String sessionId = "0";
        private String dataContent = "";
        private bool ack = false;
        private String ackId = "";
        private int retryCount = 0;

        public Packet() { }

        public int Type
        {
            get
            {
                return type;
            }

            set
            {
                type = value;
            }
        }

        public string SubType
        {
            get
            {
                return subType;
            }

            set
            {
                subType = value;
            }
        }

        public string SessionId
        {
            get
            {
                return sessionId;
            }

            set
            {
                sessionId = value;
            }
        }

        public string DataContent
        {
            get
            {
                return dataContent;
            }

            set
            {
                dataContent = value;
            }
        }

        public bool Ack
        {
            get
            {
                return ack;
            }

            set
            {
                ack = value;
            }
        }

        public string AckId
        {
            get
            {
                return ackId;
            }

            set
            {
                ackId = value;
            }
        }

        internal Packet clone()
        {
            Packet packet = new Packet();
            packet.Type = (this.type);
            packet.DataContent=(this.dataContent);
            packet.SessionId=(this.sessionId);
            packet.Ack = (this.ack);
            packet.AckId=(this.ackId);
            packet.SubType=(this.subType);
            return packet;
        }

        [JsonIngoreAttribute]
        public int RetryCount
        {
            get
            {
                return retryCount;
            }

            set
            {
                retryCount = value;
            }
        }

        public string toJsonString()
        {
            return JsonUtil.object2JsonString(this);
        }

        public byte[] toBytes()
        {
            return CharsetHelper.getBytes(toJsonString());
        }
    }
}
